package com.inter.service.impl;

import com.inter.mapper.SequenceMapper;
import com.inter.service.SequenceService;
import com.inter.utils.sequence.DateUtils;
import com.inter.utils.sequence.SequenceHepler;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 生成序列号
 *
 * @author lm
 * @date 2021/5/27 15:20
 */

@Service
public class SequenceServiceImpl implements SequenceService {
    @Resource
    SequenceMapper sequenceMapper;
    private String PACKAGES_SEQ = "seq_getPackages_connseqno";
    private String ORDER_NO_SEQ = "seq_orderNo_connseqno";

    /**
     * 生成connSeqNo流水号
     *
     * @return
     */
    @Override
    public String getPackageTaskNo() {
        String timeFix = DateUtils.format(new Date(), "yyyyMMdd");
        return SequenceHepler.generateSequence(
                /** 前缀 */
                String.format("%s%s", "F0001", timeFix),
                /** 当前序号值 */
                sequenceMapper.findCurrentVal(PACKAGES_SEQ),
                /** 数值长度 */
                10);
    }

    /**
     * 给第三方先给个假的的订单号，领科平台自己生成 orderNo
     *
     * @return
     */
    @Override
    public String getOrderNoTaskNo() {
        String timeFix = DateUtils.format(new Date(), "yyyyMMddHHMMss");
        return SequenceHepler.generateSequence(
                /** 前缀 */
                String.format("%s%s", "N", timeFix),
                /** 当前序号值 */
                sequenceMapper.findCurrentVal(ORDER_NO_SEQ),
                /** 随机数数值长度 */
                4);
    }


}
